package com.ztrue.framework.core.event;

import com.ztrue.framework.core.domain.IAggregateRoot;
import com.ztrue.framework.infrastructure.IClone;
import com.ztrue.framework.infrastructure.IDistribute;

/**
 * 表示一个领域事件消息
 *
 * @author zhangw
 * @date 2016/11/6 22:04
 * @version: 1.0
 */
public class DomainEventMessage implements IClone<DomainEventMessage>, IDistribute {
    /**
     * 领域对象聚合根
     */
    private IAggregateRoot aggregateRoot;
    /**
     * 表示一个领域事件消息
     */
    private IDomainEvent message;

    /**
     * 初始化一个默认的领域事件消息
     */
    public DomainEventMessage() {
    }

    /**
     * 初始化一个领域事件消息
     *
     * @param aggregateRoot
     * @param domainEvent
     */
    public DomainEventMessage(IAggregateRoot aggregateRoot, IDomainEvent domainEvent) {
        this.aggregateRoot = aggregateRoot;
        this.message = domainEvent;
    }

    public IAggregateRoot getAggregateRoot() {
        return aggregateRoot;
    }

    /**
     * 获取领域事件消息
     *
     * @return
     */
    public IDomainEvent getMessage() {
        return message;
    }

    /**
     * 克隆
     *
     * @param domainEventMessage
     */
    @Override
    public void clone(DomainEventMessage domainEventMessage) {
        this.aggregateRoot = domainEventMessage.getAggregateRoot();
        this.message = domainEventMessage.getMessage();
    }

    /**
     * 获取路由密匙
     *
     * @return
     */
    @Override
    public String getRoutingKey() {
        return this.message.getRoutingKey();
    }
}
